package com.itheima.train.manager.order.controller;

import com.itheima.train.manager.domain.OrderHandler;
import com.itheima.train.manager.domain.OrderParams;
import com.itheima.train.manager.domain.ResponseResult;
import com.itheima.train.manager.order.service.OrderService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/order")
@CrossOrigin(origins = "http://www.trainmanager.com")
// @Slf4j
public class OrderController {
    
    // 日志记录器对象
    private Logger log = LoggerFactory.getLogger(OrderController.class);
    
    @Autowired
    private OrderService orderService;
    
    @RequestMapping(value = "/submitOrder")
    public ResponseResult<String> submitOrder(@RequestBody OrderParams orderParams) {
        // 测试nginx限流时候使用
        // try {
        //     log.info("消费中注意时间");
        //     Thread.sleep(3000);
        // } catch (InterruptedException e) {
        //     e.printStackTrace();
        // }
        return orderService.submitOrder(orderParams);
    }
    
    @RequestMapping(value = "/queryQueue")
    public ResponseResult<String> queryQueue(@RequestBody OrderParams orderParams) {
        return orderService.querySortedInfo(orderParams);
    }
    
    @RequestMapping(value = "/queryById/{orderId}")
    public OrderHandler queryById(@PathVariable(value = "orderId") Long orderId) {
        return orderService.queryById(orderId);
    }
    
}
